package com.dycx.user.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.*;

/**
 * @author vip等级
 * @date 2023/2/23
 */
@Getter
@AllArgsConstructor
public enum VipGradeEnum {
    NORMAL(1, "普通", 0),
    BRONZE(2, "青铜", 10),
    SILVER(3, "白银", 15),
    GOLD(4, "黄金", 20),
    PLATINUM(5, "铂金", -1),
    DIAMOND(6, "钻石", -1);

    private final Integer code;
    private final String name;
    private final Integer downloadNum;


    public static VipGradeEnum converter(Integer code) {
        return Arrays.stream(values()).filter(en -> en.code.equals(code)).findAny().orElse(NORMAL);
    }

    /**
     * 转为数据
     *
     * @return 枚举对象数组
     */
    public static List<Map<String, Object>> getList() {
        List<Map<String, Object>> list = new ArrayList<>();
        for (VipGradeEnum item : VipGradeEnum.values()) {
            Map<String, Object> map = new HashMap<>();
            map.put("code", item.getCode());
            map.put("name", item.getName());
            map.put("downloadNum", item.getDownloadNum());
            list.add(map);
        }
        return list;
    }
}
